<?php

namespace app\admin\controller;


use think\Paginator;
use think\paginator\driver\Bootstrap;
use think\Request;
use think\Db;
use think\Session;
use think\Controller\redirect;
use think\Controller;
use app\admin\controller\AdminController;


class Index extends AdminController
{
    public function index()
    {
        $list = Db::name('user')->order('id asc')->field('id,username')->select();
        // $data = Db::name('user')->field('id,username,name')->paginate(1);
        foreach($list as $v){
            $role_ids = Db::name('user_role')->field('rid')
                ->where(array('uid'=>array('eq',$v['id'])))
                ->select();
            $roles = array();

            foreach ($role_ids as $value) {
                $roles[] = Db::name('role')
                    ->where(array('id'=>array('eq',$value['rid'])))
                    ->value('name');
            }
            $v['role'] = $roles;

            $arr[] = $v;
        }
        $lists = Db::name('index_user')->order('user_id asc')->field('user_id,username')->paginate(3);
        return view('index/index',[
            'list'=> $arr,
            'lists'=>$lists
        ]);
    }
    public function demo()
    {
        sendTemplateSMS($_POST['phone'], array($_POST['rand'],1), 1);
    }

    public function mail()
    {
        stmpMail();
    }
    /**
     * 后台登录页面
     * @return \think\response\View
     */
    // public function index()
    // {
    //     return view('admin@index/login');
    // }
}
